<?php

namespace App\Http\Controllers\QingShanSupplier;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\QingShanERP\Logistics;

class LogisticsController extends Controller
{
    public function getList(Request $req)
    {
        try {
            $page = $req->input('page', 0);
            $size = $req->input('size', 10);
            $type = $req->input('type', 0);
            $key = $req->input('key', '');
            $list = Logistics::where(function ($q) use ($type) {
                if ($type != 0) {
                    $q->where('type', $type);
                }
            })->where(function ($q) use ($key) {
                if ($key != '') {
                    $q->where('logistics_company', 'like', '%' . $key . '%');
                }
            })->where('del_flag', 0)->offset(($page - 1) * $size)->limit($size)->orderBy('id', 'desc')->get();
            $count = Logistics::where(function ($q) use ($type) {
                if ($type != 0) {
                    $q->where('type', $type);
                }
            })->where(function ($q) use ($key) {
                if ($key != '') {
                    $q->where('logistics_company', 'like', '%' . $key . '%');
                }
            })->where('del_flag', 0)->count();
            $res = ['list' => $list, 'total' => $count];
            return $this->resData(200, '获取数据成功...', $res);
        } catch (\Throwable $e) {
            return $this->resData(500, '获取数据失败，请稍后再试...');
        }
    }
}
